import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:liquid_swipe/liquid_swipe.dart';
import 'package:sainbainu/common/values/colors.dart';
import 'package:sainbainu/common/widgets/widget.dart';

import 'index.dart';

class WelcomePage extends StatelessWidget {
  const WelcomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return AgreePolicyDialog(
      child: Scaffold(
        body: _buildBody(),
      ),
    );
  }

  Widget _buildBody() {
    return Stack(
      alignment: AlignmentDirectional.center,
      children: [
        GetBuilder<WelcomeController>(
          builder: (_) {
            return LiquidSwipe(
              enableLoop: false,
              slideIconWidget:
                  _.state.pageIndex == 2 ? null : const Icon(Icons.arrow_back),
              enableSideReveal: true,
              onPageChangeCallback: _.onPageChange,
              pages: [
                Container(color: Colors.greenAccent),
                Container(color: Colors.blueAccent),
                Container(color: Colors.amber),
              ],
            );
          },
        ),
        Positioned(
          top: 100,
          child: Image.asset(
            'assets/images/logo.png',
            width: 300 / 2,
            height: 67 / 2,
          ),
        ),
        Positioned(
          bottom: 100,
          child: GetBuilder<WelcomeController>(
            builder: (_) {
              if (_.state.pageIndex == 0) {
                return const Text(
                  '欢迎语句或介绍1',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                );
              } else if (_.state.pageIndex == 1) {
                return const Text(
                  '欢迎语句或介绍2',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                  ),
                );
              } else {
                return ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    backgroundColor: AppColors.danger,
                    foregroundColor: Colors.white,
                  ),
                  onPressed: _.onGo,
                  child: Text('开始旅行'.tr),
                );
              }
            },
          ),
        ),
      ],
    );
  }
}
